package com.up.cloudfeiyibackend.controller;

import com.up.cloudfeiyibackend.constant.EventMessageConstant;
import com.up.cloudfeiyibackend.dto.*;
import com.up.cloudfeiyibackend.entity.EventApplication;
import com.up.cloudfeiyibackend.result.PageResult;
import com.up.cloudfeiyibackend.result.Result;
import com.up.cloudfeiyibackend.service.EventService;
import com.up.cloudfeiyibackend.vo.*;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 非遗活动相关接口
 */
@RestController
@RequestMapping("/event")
@RequiredArgsConstructor
public class EventController {

    @Autowired
    private final EventService eventService;

    /**
     * 分页查询所有非遗活动
     *
     * @return
     */
    @GetMapping("/pageQuery")
    public Result<PageResult<EventVO>> page(EventPageDto eventPageDto) {
        PageResult<EventVO> result = eventService.page(eventPageDto);
        return Result.success(EventMessageConstant.EVENT_MESSAGE, result);
    }

    /**
     * 查询所有活动分类
     *
     * @return
     */
    @GetMapping("/category")
    public Result<List<EventCategoryVO>> getEventCategory() {
        List<EventCategoryVO> result = eventService.getEventCategory();
        return Result.success(EventMessageConstant.EVENT_MESSAGE, result);
    }

    /**
     * 查询所有活动区域
     *
     * @return
     */
    @GetMapping("/regions")
    public Result<List<EventRegionVO>> getEventRegions() {
        return eventService.getEventRegions();
    }

    /**
     * 查询指定分类的活动数量
     *
     * @param categoryId
     * @return
     */
    @GetMapping("/countByCategory")
    public Result<Integer> getEventCountByCategory(Long categoryId) {
        Integer result = eventService.getEventCountByCategory(categoryId);
        return Result.success(EventMessageConstant.EVENT_MESSAGE, result);
    }

    /**
     * 查询活动详情
     *
     * @param eventId
     * @return
     */
    @GetMapping("/detail/{eventId}")
    public Result<EventDetailVO> getEventDetail(@PathVariable Long eventId) {

        EventDetailVO result = eventService.getEventDetail(eventId);
        return Result.success(EventMessageConstant.EVENT_MESSAGE, result);
    }


    /**
     * 报名活动
     *
     * @param
     * @return
     */
    @PostMapping("/signUp")
    public Result EventSignUp(@RequestBody EventSignupDto eventSignUpDto) {
        return eventService.signUp(eventSignUpDto);
    }


    /**
     * 查询报名活动以及状态
     *
     * @return
     */
    @GetMapping("/signupStatus")
    public Result<List<EventSignupStatusVO>> getEventSignupStatus() {
        return eventService.getEventSignupStatus();
    }


    /**
     * 新增评论
     *
     * @return
     */
    @PostMapping("/addComment")
    public Result addEventComment(@RequestBody EventCommentsDto eventCommentsDto) {
        return eventService.addEventComment(eventCommentsDto);
    }

    /**
     * 删除评论
     *
     * @param eventCommentId
     * @return
     */
    @DeleteMapping("/deleteComment/{eventCommentId}")
    public Result deleteEventComment(@PathVariable Long eventCommentId) {
        return eventService.deleteEventComment(eventCommentId);
    }


    /**
     * 展示顶级评论
     *
     * @param EventId
     * @return
     */
    @GetMapping("/topComment/{EventId}")
    public Result<List<EventCommentsVO>> getAllEventTopComment(@PathVariable Long EventId) {
        return eventService.getAllEventTopComment(EventId);
    }

    /**
     * 展示评论回复
     *
     * @param
     * @return
     */
    @GetMapping("/reply")
    public Result<List<EventCommentsReplyVO>> listReplysByEventId(EventCommentsReplyDto eventCommentsReplyDto) {
        return eventService.listReplysByEventId(eventCommentsReplyDto);
    }


    /**
     * 非遗传承人发布活动
     *
     * @param eventApplicationDto
     * @return
     */
    @PostMapping("/application")
    public Result EventApplication(@RequestBody EventApplicationDto eventApplicationDto) {
        return eventService.EventApplication(eventApplicationDto);
    }


    /**
     * 获取当前用户所申请的活动申请表
     *
     * @return
     */
    @GetMapping("/application")
    public Result<List<EventApplicationVO>> getAllEventApplication() {
        return eventService.getAllEventApplication();
    }


    /**
     *
     * 获取回复当前用户评论中未被用户查看的总数
     * @return
     */
    @GetMapping("/commentCount")
    public Result<Integer> getNovIEWCommentCount(){
        return eventService.getNovIEWCommentCount();
    }


    /**
     *
     * 获取所有回复当前用户评论的评论
     * @return
     */
    @GetMapping("/notification/comment")
    public Result<List<ReplyCommentNotificationVO>> getNoViewCommentNotification(){
        return eventService.getNoViewCommentNotification();
    }
}
